﻿@page "/registry"
@inject IStringLocalizer<Merp.Wasm.App.Resources.Registry.Index> localizer

<div class="row">
    <EditForm Model="@Params" OnValidSubmit="@Search" class="col-md-12">
        <div class="form-row">
            <div class="col-md-4">
                <div class="form-group row">
                    <label class="col-md-2 col-form-label" for="partyType">@localizer[nameof(Merp.Wasm.App.Resources.Registry.Index.PartyTypeSelectLabel)]</label>
                    <div class="col-md-10">
                        <InputSelect @bind-Value="Params.PartyType" class="form-control">
                            <option value=" ">@localizer[nameof(Merp.Wasm.App.Resources.Registry.Index.PartyTypeSelectAny)]</option>
                            <option value="person">@localizer[nameof(Merp.Wasm.App.Resources.Registry.Index.PartyTypeSelectPerson)]</option>
                            <option value="company">@localizer[nameof(Merp.Wasm.App.Resources.Registry.Index.PartyTypeSelectCompany)]</option>
                        </InputSelect>
                    </div>
                </div>
            </div>

            <div class="col-md-4">
                <div class="form-group row">
                    <label class="col-md-2 col-form-label" for="query">@localizer[nameof(Merp.Wasm.App.Resources.Registry.Index.DisplayName)]</label>
                    <div class="col-md-10">
                        <InputText @bind-Value="Params.PartyName" class="form-control" type="search" />
                    </div>
                </div>
            </div>

            <div class="col-md-4">
                <div class="form-group row">
                    <label class="col-md-3 col-form-label" for="sort">@localizer[nameof(Merp.Wasm.App.Resources.Registry.Index.SortOrderSelectLabel)]</label>
                    <div class="col-md-9">
                        <InputSelect @bind-Value="Params.Order" class="form-control">
                            @foreach (var sortOrder in Enum.GetValues(typeof(SortOrder)))
                            {
                                <option value="@sortOrder">@sortOrder</option>
                            }
                        </InputSelect>
                    </div>
                </div>
            </div>

            <div class="col-md-4">
                <div class="form-group row">
                    <label class="col-md-2 col-form-label" for="city">@localizer[nameof(Merp.Wasm.App.Resources.Registry.Index.CityLabel)]</label>
                    <div class="col-md-10">
                        <InputText @bind-Value="Params.CityName" class="form-control" type="search" />
                    </div>
                </div>
            </div>

            <div class="col-md-4">
                <div class="form-group row">
                    <label class="col-form-label col-md-4" for="city">@localizer[nameof(Merp.Wasm.App.Resources.Registry.Index.PostalCodeLabel)]</label>
                    <div class="col-md-8">
                        <InputText @bind-Value="Params.PostalCode" class="form-control" type="search" />
                    </div>
                </div>
            </div>
        </div>
        <div class="form-row">
            <div class="col-md-6">
                <button type="button" class="btn btn-primary" @onclick="Search">
                    <i class="fas fa-search"></i>
                    @localizer[nameof(Merp.Wasm.App.Resources.Registry.Index.SearchButtonText)]
                </button>
            </div>
            <div class="col-md-6">
                <div class="btn-group float-right" role="group">
                    <NavLink class="btn btn-outline-secondary" href="/registry/company/add">
                        <i class="fas fa-plus"></i> @localizer[nameof(Merp.Wasm.App.Resources.Registry.Index.AddCompanyButtonText)]
                    </NavLink>
                    <NavLink class="btn btn-outline-secondary" href="/registry/person/add">
                        <i class="fas fa-plus"></i> @localizer[nameof(Merp.Wasm.App.Resources.Registry.Index.AddPersonButtonText)]
                    </NavLink>
                </div>
            </div>
        </div>
    </EditForm>
</div>
<div class="row">
    <hr />
    @if (Model.TotalNumberOfParties > 0)
    {
        <text>
            <p>
                @Params.PageSize of @Model.TotalNumberOfParties items
            </p>
        </text>
    }
    <hr />

    <table class="table table-striped">
        <thead>
            <tr>
                <th>@localizer[nameof(Merp.Wasm.App.Resources.Registry.Index.NameColumn)]</th>
                <th>@localizer[nameof(Merp.Wasm.App.Resources.Registry.Index.SSNColumn)]</th>
                <th>@localizer[nameof(Merp.Wasm.App.Resources.Registry.Index.VatNumberColumn)]</th>
                <th>@localizer[nameof(Merp.Wasm.App.Resources.Registry.Index.PhoneColumn)]</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            @foreach (var party in Model.Parties)
            {
                <tr>
                    <td>@party.Name</td>
                    <td>@party.NationalIdentificationNumber</td>
                    <td>@party.VatIndex</td>
                    <td>@party.PhoneNumber</td>
                    <td></td>
                </tr>
            }
        </tbody>
    </table>
</div>